package com.sinosoft.cloud.access.codec;

import com.sinosoft.cloud.access.annotations.AccessCoder;
import com.sinosoft.cloud.access.net.Access;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.AnnotationUtils;

import javax.annotation.PostConstruct;

/**
 * cloud-netty
 *
 * @title: cloud-netty
 * @package: com.sinosoft.cloud.access.codec
 * @author: yangming
 * @date: 2017/12/2 下午3:31
 */
public abstract class CoderBean implements Decoder, Access {

    protected final Log logger = LogFactory.getLog(getClass());

    private String accessName = null;
    private Integer port = null;

    @Override
    public String getAccessName() {
        return accessName;
    }

    @Override
    public void setAccessName(String accessName) {
        this.accessName = accessName;
    }

    @Override
    public Integer getPort() {
        return port;
    }

    @Override
    public void setPort(Integer port) {
        this.port = port;
    }

    @PostConstruct
    public void init() {
        AccessCoder coder = AnnotationUtils.findAnnotation(this.getClass(), AccessCoder.class);
        setAccessName(coder.name());
        DecoderFactory decoderFactory = DecoderFactory.getInstance();
        decoderFactory.addDecoder(getAccessName(), this);
    }
}
